/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-08-10 15:51:48
 * @LastEditTime: 2022-08-10 17:03:59
 * @LastEditors: liutq
 * @Reference:
 */
package job

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/maxyang107/jinglan/model"
	"github.com/maxyang107/jinglan/model/user"
)

type OrderInfo struct {
	OrderId    string
	Expiretime time.Time
}

func DealOrderExpertime() {
	fmt.Println("异步任务启动成功……")
	go func() {
		for {
			s := model.Consumer()
			if len(s) < 2 {
				time.Sleep(time.Second * 60)
				continue
			}
			var orderinfo OrderInfo
			json.Unmarshal([]byte(s[1]), &orderinfo)
			if orderinfo.Expiretime.Before(time.Now()) {
				err := user.RmExpertimeOrder(orderinfo.OrderId)
				if err != nil {
					model.AddJob(orderinfo.OrderId, orderinfo.Expiretime)
				}
			} else {
				model.AddJob(orderinfo.OrderId, orderinfo.Expiretime)
			}
		}
	}()

}
